package com.weitu.majorHazard.assessmentReport.service.impl;

import com.weitu.accessory.util.AccessoryUtil;
import com.weitu.majorHazard.assessmentReport.entity.AssessmentReport;
import com.weitu.majorHazard.assessmentReport.mapper.AssessmentReportMapper;
import com.weitu.majorHazard.assessmentReport.service.AssessmentReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/4/24.
 */
@Service
public class AssessmentReportServiceImpl implements AssessmentReportService{

    private final AssessmentReportMapper assessmentReportMapper;

    @Autowired
    public AssessmentReportServiceImpl(AssessmentReportMapper assessmentReportMapper){
        this.assessmentReportMapper=assessmentReportMapper;
    }

    @Override
    public int queryCount(Map<String, Object> map) {
        return this.assessmentReportMapper.queryCount(map);
    }

    @Override
    public List<AssessmentReport> queryList(Map<String, Object> map) {
        return this.assessmentReportMapper.queryList(map);
    }

    @Override
    @Transactional
    public boolean insertAssessmentReport(AssessmentReport assessmentReport) {
        boolean flag2=false;
        int count=this.assessmentReportMapper.insertAssessmentReport(assessmentReport);
        if(count==1)
            flag2=true;
        boolean flag= AccessoryUtil.saveAccerssoryInfo(assessmentReport.getId());
        return flag&&flag2;
    }

    @Override
    public AssessmentReport queryAssessmentReportById(String id) {
        return this.assessmentReportMapper.queryAssessmentReportById(id);
    }

    @Override
    @Transactional
    public boolean updateAssessmentReport(AssessmentReport assessmentReport) {
        boolean flag2=false;
        int count= this.assessmentReportMapper.updateAssessmentReport(assessmentReport);
        if(count==1)
            flag2=true;
        boolean flag= AccessoryUtil.saveAccerssoryInfo(assessmentReport.getId());
        return flag&&flag2;
    }

    @Override
    public int deleteAssessmentReport(String id) {
        return this.assessmentReportMapper.deleteAssessmentReport(id);
    }
}
